﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using ch.froorider.NGoogleCalendar.facade;
using ch.froorider.NGoogleCalendar.facade.businessObjects;

namespace ch.froorider.NGoogleCalendar
{
	/// <summary>
	/// Core class of the library. Handles all requests from and to the different clients (GUI and ATOM Feed).
	/// Implements the Contract between the client and the "server".
	/// </summary>
	internal class NGoogleCalendar : IGoogleCalendar
	{

		/// <summary>
		/// Constructor. Inits all the necessary stuff.
		/// </summary>
		internal NGoogleCalendar()
		{
			//Do the init stuff for ATOM FEED etc.
		}

		#region IGoogleCalendar Members

		/// <summary>
		/// Gives you a list of all available (persitent) users.
		/// </summary>
		/// <returns></returns>
		public List<User> GetAllUsers()
		{
			List<User> users = new List<User>();
			return users;
		}

		/// <summary>
		/// Stores a new user in the DB and if possible on the Web.
		/// </summary>
		/// <param name="newUser"></param>
		/// <returns></returns>
		public bool SaveNewUser(User newUser)
		{
			try
			{
				newUser.PropertyChanged += new PropertyChangedEventHandler(BusinessObjectChanged);
				return true;
			}
			catch (Exception)
			{
				return false;
			}
		}


		#endregion

		#region Event handling

		private void BusinessObjectChanged(object businessObject, PropertyChangedEventArgs args)
		{
			Console.WriteLine("Business object changed: " + args.PropertyName);
		}
		
		#endregion
	}
}
